package cn.com.headfree.point.service.impl;

import cn.com.headfree.entity.TPointRuleInfo;
import cn.com.headfree.entity.TRuleElementInfo;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.point.dao.PointRuleDao;
import cn.com.headfree.point.dao.RuleElementDao;
import cn.com.headfree.point.service.PointRuleService;
import cn.com.headfree.point.service.RuleElementService;
import com.gta.edu.sdk.common.dto.Page;
import com.gta.edu.sdk.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service("ruleElementService")
@Transactional
public class RuleElementServiceImpl implements RuleElementService {

	private static final Logger log = LogManager.getLogger(RuleElementServiceImpl.class);

	@Autowired
	private RuleElementDao ruleElementDao;

	@Override
	public void findRuleElementPageListByProjectId(Page<TRuleElementInfo> page,TRuleElementInfo ruleElementInfo) {
		ruleElementDao.findRuleElementPageListByProjectId(page,ruleElementInfo);
	}

	@Override
	public void saveElementInfo(TRuleElementInfo ruleElementInfo,User user) {
		ruleElementInfo.setUpdaterId(user.getFax());
		ruleElementInfo.setUpdaterName(user.getName());
		ruleElementInfo.setUpdateTime(new Date());
		if(StringUtil.isNullOrEmpty(ruleElementInfo.getId())){
			ruleElementInfo.setOrgId(user.getBaseOrgId());
			ruleElementInfo.setOrgName(user.getBaseOrgName());
			ruleElementInfo.setCreaterId(user.getFax());
			ruleElementInfo.setCreaterName(user.getName());
			ruleElementInfo.setCreateTime(new Date());
			ruleElementInfo.setDelSign(0);
			ruleElementDao.saveRuleElementInfo(ruleElementInfo);
		}else{
			ruleElementDao.updateRuleElementInfo(ruleElementInfo);
		}
	}
	

	@Override
	public void deleteElementInfo(TRuleElementInfo ruleElementInfo) {
		ruleElementDao.deleteRuleElementInfo(ruleElementInfo);
	}

	@Override
	public List<TRuleElementInfo> getRuleElementInfoByRuleIdAndMouldId(String ruleId, String mouldId,String orgId) {
		return ruleElementDao.getRuleElementInfoByRuleIdAndMouldId(ruleId,mouldId,orgId);
	}
}
